/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuPescaGratis.java
 *
 * Created on 13/01/2010, 12:09:27
 */

package JPaneis;

import Conector.Conector;
import Data.Cliente;
import java.awt.Component;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import siii.MenuPadrao;


/**
 *
 * @author Ricardo
 */
public class MenuPescaGratis extends javax.swing.JPanel {
    private boolean vendaRealizada;
    private boolean clienteEncontrado;
    private boolean valorCalculado;
    private final ImageIcon iconeOK;
    private final ImageIcon iconeERRO;
    private final ImageIcon iconeATENCAO;
    private Conector conector;
    private float total;
    private final MenuPadrao menuPadrao;
    private Cliente pescador;
    private List<Map<String, ?>> lista;
    private static final String numServ = "NUMERO_SERVICO";
    private int numero_do_servico_selecionado;
    private int contador = 0;

    /** Creates new form MenuPescaGratis */
    public MenuPescaGratis(MenuPadrao m, Conector con) {
        this.menuPadrao = m;
        this.conector = con;
        initComponents();
        clienteEncontrado = false;
        valorCalculado = false;
        vendaRealizada = false;
        iconeOK = new ImageIcon(getClass().getResource("/Images/fish-48x48ok.png"));
        iconeERRO = new ImageIcon(getClass().getResource("/Images/fish-48x48erro.png"));
        iconeATENCAO = new ImageIcon(getClass().getResource("/Images/fish-48x48atencao1.png"));
        jButtonConfirmar.setVisible(false);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pescTotal = new javax.swing.JLabel();
        jLabelTotal = new javax.swing.JLabel();
        jButtonConfirmar = new javax.swing.JButton();
        real2 = new javax.swing.JLabel();
        jButtonCancelar = new javax.swing.JButton();
        jLabelServicoPesca = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        pescNome = new javax.swing.JFormattedTextField();
        pescSobrenome = new javax.swing.JFormattedTextField();
        jButtonConsultar = new javax.swing.JButton();
        pescNumPescador = new javax.swing.JFormattedTextField();
        jLabelSobrenome = new javax.swing.JLabel();
        jLabelCPF = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        pescCPF = new javax.swing.JFormattedTextField();
        jLabelNumPescador = new javax.swing.JLabel();
        jLabelServicoPesca1 = new javax.swing.JLabel();
        jScrollPaneServPesc = new javax.swing.JScrollPane();
        jListConfirmacaoDeComprovantesEmitidos = new javax.swing.JList();
        jButtonConfirmarComprovanteSelecionado = new javax.swing.JButton();
        jLabelPeriodo = new javax.swing.JLabel();
        jLabelMasculino = new javax.swing.JLabel();
        jLabelFeminino = new javax.swing.JLabel();
        pescMasculino = new javax.swing.JComboBox();
        jLabelQuantidade = new javax.swing.JLabel();
        pescFeminino = new javax.swing.JComboBox();
        jLabelTurno = new javax.swing.JLabel();
        pescTurno = new javax.swing.JComboBox();
        pescPeriodo = new javax.swing.JComboBox();
        pescPeriodo1 = new javax.swing.JComboBox();
        jLabelConfirmado = new javax.swing.JLabel();
        jLabelContador = new javax.swing.JLabel();

        pescTotal.setText("0.00");

        jLabelTotal.setText("Valor Total");

        jButtonConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_add.png"))); // NOI18N
        jButtonConfirmar.setText("Confirmar / Imprimir");
        jButtonConfirmar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonConfirmarMouseClicked(evt);
            }
        });
        jButtonConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmarActionPerformed(evt);
            }
        });

        real2.setText("R$");

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/peixe_cancelar.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonCancelarmouseClickedCancelarHandler(evt);
            }
        });

        jLabelServicoPesca.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabelServicoPesca.setText("Pesca Grátis");
        jLabelServicoPesca.setToolTipText("Para um serviço poder ser realizado existe a necessidade de preencher algum dos campos abaixo");

        pescNome.setToolTipText("Digite o nome do Pescador");

        pescSobrenome.setToolTipText("Digite o Sobrenome do Pescador");

        jButtonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/fish-48x48buscar.png"))); // NOI18N
        jButtonConsultar.setText("Consultar");
        jButtonConsultar.setToolTipText("Com algum dos dados preenchidos o Consultar procura o Cliente e preenche os demais campos");
        jButtonConsultar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonConsultarmouseClickedBuscar(evt);
            }
        });

        pescNumPescador.setToolTipText("Digite o numero do pescador");

        jLabelSobrenome.setText("Sobrenome");

        jLabelCPF.setText("C.P.F");

        jLabelNome.setText("Nome");

        pescCPF.setToolTipText("Digite o CPF");

        jLabelNumPescador.setText("Número do Pescador");

        jLabelServicoPesca1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabelServicoPesca1.setText("Confirmação de comprovantes emitidos");
        jLabelServicoPesca1.setToolTipText("Para um serviço poder ser realizado existe a necessidade de preencher algum dos campos abaixo");

        jListConfirmacaoDeComprovantesEmitidos.setName("Lista de Cadastro de Setviço de Pesca"); // NOI18N
        jListConfirmacaoDeComprovantesEmitidos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListConfirmacaoDeComprovantesEmitidosMouseClicked(evt);
            }
        });
        jListConfirmacaoDeComprovantesEmitidos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListConfirmacaoDeComprovantesEmitidosValueChanged(evt);
            }
        });
        jScrollPaneServPesc.setViewportView(jListConfirmacaoDeComprovantesEmitidos);

        jButtonConfirmarComprovanteSelecionado.setText("Confirmar");
        jButtonConfirmarComprovanteSelecionado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonConfirmarComprovanteSelecionadoMouseClicked(evt);
            }
        });

        jLabelPeriodo.setText("Período");

        jLabelMasculino.setText("Masculino");

        jLabelFeminino.setText("Feminino");

        pescMasculino.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1" }));
        pescMasculino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pescMasculinoActionPerformed(evt);
            }
        });

        jLabelQuantidade.setText("Quantidade");

        pescFeminino.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1" }));
        pescFeminino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pescFemininoActionPerformed(evt);
            }
        });

        jLabelTurno.setText("Turno");

        pescTurno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Diurno", "Noturno" }));
        pescTurno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pescTurnoActionPerformed(evt);
            }
        });

        pescPeriodo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Integral", "Meio-Período" }));
        pescPeriodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pescPeriodoActionPerformed(evt);
            }
        });

        pescPeriodo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Integral", "Meio-Período" }));
        pescPeriodo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pescPeriodo1ActionPerformed(evt);
            }
        });

        jLabelConfirmado.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelConfirmado.setForeground(new java.awt.Color(51, 51, 255));
        jLabelConfirmado.setText("Confirmado:");

        jLabelContador.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabelContador.setText("0");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(177, 177, 177)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelSobrenome)
                                    .addComponent(jLabelNome))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(pescSobrenome, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelCPF)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(pescCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(pescNome, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelNumPescador)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(pescNumPescador, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 971, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPaneServPesc, javax.swing.GroupLayout.PREFERRED_SIZE, 653, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(30, 30, 30)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelFeminino)
                                            .addComponent(jLabelMasculino))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addGap(16, 16, 16)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(pescMasculino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(pescFeminino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(46, 46, 46))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabelQuantidade)
                                                .addGap(37, 37, 37)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabelTurno)
                                            .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabelPeriodo)
                                                    .addComponent(pescPeriodo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(pescTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(312, 312, 312)
                                        .addComponent(pescPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonConfirmar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonCancelar))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(78, 78, 78)
                                        .addComponent(jLabelConfirmado)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelContador, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(63, 63, 63)
                                        .addComponent(jLabelTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(25, 25, 25)
                                        .addComponent(real2)
                                        .addGap(18, 18, 18)
                                        .addComponent(pescTotal))))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelServicoPesca1, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonConfirmarComprovanteSelecionado))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jLabelServicoPesca, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(310, 310, 310)
                .addComponent(pescPeriodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(225, 225, 225))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelServicoPesca, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelNumPescador)
                            .addComponent(pescNumPescador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelNome)
                            .addComponent(pescNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelSobrenome)
                            .addComponent(pescSobrenome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelCPF)
                            .addComponent(pescCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jButtonConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelServicoPesca1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonConfirmarComprovanteSelecionado))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelContador)
                            .addComponent(jLabelConfirmado))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelQuantidade)
                            .addComponent(jLabelTurno))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(pescMasculino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelMasculino)
                            .addComponent(pescTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelPeriodo)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(pescFeminino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabelFeminino)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pescPeriodo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelTotal)
                            .addComponent(pescTotal)
                            .addComponent(real2))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonCancelar)
                            .addComponent(jButtonConfirmar)))
                    .addComponent(jScrollPaneServPesc, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(89, 89, 89))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonConfirmarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonConfirmarMouseClicked
        // TODO add your handling code here:
        Date data_atendimento = null;
        vendaRealizada = false;
        if(clienteEncontrado) {
                    conector.insereServicoPescaGratis(pescTurno.getSelectedItem().toString(),
                            pescPeriodo.getSelectedItem().toString(),
                            (Integer.parseInt(pescMasculino.getSelectedItem().toString())+
                            Integer.parseInt(pescFeminino.getSelectedItem().toString())),
                            total,
                            Integer.parseInt(pescNumPescador.getText()),
                            "Pesca Grátis, realizada após a apresentação de 10 comprovantes");
                    JOptionPane.showMessageDialog(this, "Servico realizado com sucesso", "Atenção", JOptionPane.WARNING_MESSAGE, iconeOK);
                    vendaRealizada = true;
                    //                  List<Map<String,?>> dadosServico =  conector.doRawSql("SELECT TOP 1 * FROM SERVICOS_REALIZADOS_PESCA");

                    List<Map<String,?>> dadosServico =  conector.doRawSql("SELECT MAX(NUMERO_SERVICO) AS  NUMERO_SERVICO FROM SERVICOS_REALIZADOS_PESCA");

                    List<Map<String,?>> dadosPesqueiro =  conector.doRawSql("SELECT * FROM PESQUEIROS");

                    List<Map<String,?>> dadosPescador =  conector.doRawSql("SELECT * FROM CLIENTES WHERE NUMERO_DO_PESCADOR = " + pescNumPescador.getText());

                    String nomePescador = (String) dadosPescador.get(0).get("NOME");

                    String nomePesqueiro = (String) dadosPesqueiro.get(0).get("NOME");
                    String endereco = (String) dadosPesqueiro.get(0).get("LOGRADOURO");
                    String numero = (String) dadosPesqueiro.get(0).get("NUMERO");
                    String bairro = (String) dadosPesqueiro.get(0).get("BAIRRO");
                    String cidade = (String) dadosPesqueiro.get(0).get("CIDADE");
                    String estado = (String) dadosPesqueiro.get(0).get("ESTADO");
                    String cep = (String) dadosPesqueiro.get(0).get("CEP");
                    String tel = (String) dadosPesqueiro.get(0).get("TELEFONE");
                    String email = (String) dadosPesqueiro.get(0).get("EMAIL");
                    Integer ordemServico = (Integer) dadosServico.get(0).get("NUMERO_SERVICO");

                    List<Map<String,?>> dadosServico1 =  conector.doRawSql("SELECT HORARIO FROM SERVICOS_REALIZADOS_PESCA WHERE NUMERO_SERVICO = " + ordemServico);

                    String dataHorario = dadosServico1.get(0).get("HORARIO").toString();


//                    imprimirCupom(  Integer.parseInt(pescNumPescador.getText()), nomePesqueiro, tel, email, endereco, numero, bairro,
//                            cidade, estado, cep, nomePescador, (ordemServico + 1),
//                            dataHorario,
//                            pescTurno.getSelectedItem().toString(),
//                            pescPeriodo.getSelectedItem().toString(),
//                            (Integer.parseInt(pescMasculino.getSelectedItem().toString())+ Integer.parseInt(pescFeminino.getSelectedItem().toString())),
//                            total);
        } else {

            JOptionPane.showMessageDialog(this, "Favor Buscar cliente", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
        }

        if(vendaRealizada) {
            cleanScreen();
            menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
        }
}//GEN-LAST:event_jButtonConfirmarMouseClicked
    private void jButtonConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmarActionPerformed
        
}//GEN-LAST:event_jButtonConfirmarActionPerformed

    private void jButtonCancelarmouseClickedCancelarHandler(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonCancelarmouseClickedCancelarHandler
        // TODO add your handling code here:
        this.cleanScreen();
        menuPadrao.trocaPanel2(menuPadrao.getMenuPrincipal());
}//GEN-LAST:event_jButtonCancelarmouseClickedCancelarHandler

    private void jButtonConsultarmouseClickedBuscar(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonConsultarmouseClickedBuscar
        String[][] dadosRelatorio = null;
        String sexo;
        String cpf = pescCPF.getText().replace(".", "").replace("-", "").replace(" ", "");
        if (pescNumPescador.getText().length() > 0) {
            pescador = new Cliente(Integer.parseInt(pescNumPescador.getText()), pescNome.getText(), pescSobrenome.getText(), cpf);
        } else {
            pescador = new Cliente(0, pescNome.getText(), pescSobrenome.getText(), cpf);
        }
        try {

            Cliente pesc = new Cliente();
            pesc = conector.consultarClienteParaPesca(pescador, this);

            if(pesc.isFlagClienteNaoEncontrado())
                JOptionPane.showMessageDialog(this, "Cliente não encontrado", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
            else {
                setClientScreen(pesc);
                clienteEncontrado = true;
                dadosRelatorio = conector.pescaGratis(Integer.parseInt((pescNumPescador.getText())));
                sexo = conector.sexo(Integer.parseInt((pescNumPescador.getText())));
                if (sexo.compareTo("M")==0)
                {
                    pescFeminino.setVisible(false);
                    jLabelFeminino.setVisible(false);
                    pescMasculino.setSelectedIndex(1);
                }
                else
                {
                    pescMasculino.setVisible(false);
                    jLabelMasculino.setVisible(false);
                    pescFeminino.setSelectedIndex(1);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            conector = new Conector();
        }
        if(dadosRelatorio != null) {
          jListConfirmacaoDeComprovantesEmitidos.setListData(dadosRelatorio);
          //create Renderer and dislpay
         // System.out.println("Total: " + totaliza);
          jListConfirmacaoDeComprovantesEmitidos.setCellRenderer((ListCellRenderer) new MyCellRenderer(dadosRelatorio[0].length));
        }
}//GEN-LAST:event_jButtonConsultarmouseClickedBuscar

    private void pescMasculinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pescMasculinoActionPerformed
        // TODO add your handling code here:
        valorCalculado = false;
}//GEN-LAST:event_pescMasculinoActionPerformed

    private void pescFemininoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pescFemininoActionPerformed
        // TODO add your handling code here:
        valorCalculado = false;
}//GEN-LAST:event_pescFemininoActionPerformed

    private void pescTurnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pescTurnoActionPerformed
        valorCalculado = false;
        // TODO add your handling code here:
}//GEN-LAST:event_pescTurnoActionPerformed

    private void pescPeriodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pescPeriodoActionPerformed
        valorCalculado = false;
        // TODO add your handling code here:
}//GEN-LAST:event_pescPeriodoActionPerformed

    private void pescPeriodo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pescPeriodo1ActionPerformed
        valorCalculado = false;
        // TODO add your handling code here:
}//GEN-LAST:event_pescPeriodo1ActionPerformed

    private void jButtonConfirmarComprovanteSelecionadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonConfirmarComprovanteSelecionadoMouseClicked
    contador++;
    if(contador == 10)
    {
        jButtonConfirmar.setVisible(true);
    }
    if(contador > 10)
    {
        JOptionPane.showMessageDialog(this, "O número máximo de Comprovantes foi atingido.,\nPor favor, clique em Confirmar/Imprimir", "Atenção", JOptionPane.WARNING_MESSAGE, iconeERRO);
        contador = 10;
    }
    jLabelContador.setText(String.valueOf(contador));

    }//GEN-LAST:event_jButtonConfirmarComprovanteSelecionadoMouseClicked

    private void jListConfirmacaoDeComprovantesEmitidosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListConfirmacaoDeComprovantesEmitidosMouseClicked
        if(jListConfirmacaoDeComprovantesEmitidos.getSelectedIndex() != -1) {
            Map<String, ?> itens = lista.get(jListConfirmacaoDeComprovantesEmitidos.getSelectedIndex());
                Integer numeroServico = (Integer) itens.get(numServ);
            System.out.println("NUMERO DO SERVICO QUE EU QUERO: " + numeroServico);
        }
    }//GEN-LAST:event_jListConfirmacaoDeComprovantesEmitidosMouseClicked

    private void jListConfirmacaoDeComprovantesEmitidosValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListConfirmacaoDeComprovantesEmitidosValueChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_jListConfirmacaoDeComprovantesEmitidosValueChanged

    private void setClientScreen() {
        setClientScreen(pescador);
    }

    public void setClientScreen(Cliente setCli) {
        pescNumPescador.setText(String.valueOf(setCli.getNumeroPescador()));
        pescNome.setText(setCli.getNome());
        pescSobrenome.setText(setCli.getSobrenome());
        pescCPF.setText(setCli.getCpf());
    }

static class MyCellRenderer extends JPanel implements ListCellRenderer {

        ArrayList<JLabel> labels = new ArrayList();
        JLabel left, middle, right;
        int cols;

        MyCellRenderer(int cols) {
            this.cols = cols;
            setLayout(new GridLayout(1, cols));
            for (int i=0; i < cols;i++){
                JLabel label = new JLabel();
                label.setOpaque(true);
                add(label);
                labels.add(label);
            }
        }

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            int i = 0;
            for (JLabel jl : labels) {
                jl.setText(((String[])value)[i++]) ;
                if (isSelected) {
                    jl.setBackground(list.getSelectionBackground());
                    jl.setForeground(list.getSelectionForeground());
                } else {
                    jl.setBackground(list.getBackground());
                    jl.setForeground(list.getForeground());
                }
            }

            setEnabled(list.isEnabled());
            setFont(list.getFont());
            return this;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonConfirmar;
    private javax.swing.JButton jButtonConfirmarComprovanteSelecionado;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JLabel jLabelCPF;
    private javax.swing.JLabel jLabelConfirmado;
    private javax.swing.JLabel jLabelContador;
    private javax.swing.JLabel jLabelFeminino;
    private javax.swing.JLabel jLabelMasculino;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelNumPescador;
    private javax.swing.JLabel jLabelPeriodo;
    private javax.swing.JLabel jLabelQuantidade;
    private javax.swing.JLabel jLabelServicoPesca;
    private javax.swing.JLabel jLabelServicoPesca1;
    private javax.swing.JLabel jLabelSobrenome;
    private javax.swing.JLabel jLabelTotal;
    private javax.swing.JLabel jLabelTurno;
    private javax.swing.JList jListConfirmacaoDeComprovantesEmitidos;
    private javax.swing.JScrollPane jScrollPaneServPesc;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JFormattedTextField pescCPF;
    private javax.swing.JComboBox pescFeminino;
    private javax.swing.JComboBox pescMasculino;
    private javax.swing.JFormattedTextField pescNome;
    private javax.swing.JFormattedTextField pescNumPescador;
    private javax.swing.JComboBox pescPeriodo;
    private javax.swing.JComboBox pescPeriodo1;
    private javax.swing.JFormattedTextField pescSobrenome;
    private javax.swing.JLabel pescTotal;
    private javax.swing.JComboBox pescTurno;
    private javax.swing.JLabel real2;
    // End of variables declaration//GEN-END:variables

    private void cleanScreen() {
        pescNumPescador.setText("");
        pescNome.setText("");
        pescSobrenome.setText("");
        pescCPF.setText("");
        pescMasculino.setSelectedItem("0");
        pescFeminino.setSelectedItem("0");
        pescTurno.setSelectedItem("Diurno");
        pescPeriodo.setSelectedItem("Integral");
        pescTotal.setText("0.00");
        clienteEncontrado = false;
        vendaRealizada = false;
        total = 0;
        jLabelContador.setText("0");
    }
}
